<?php
namespace jy_area9fan;
defined('BY_JYA') or exit('error');
/*
	分销插件工具类
*/
class model extends \plugin{
	
	
	public function current_level_up_types(){
		return str_array($this->setting['level_up_types']);
	}
	public function available_areas(){
		$areas=file_get_contents(ROOT_D.'/core/resource/area_town.txt');
		$areas=unserialize($areas);
		return $areas;
	}
	public function get_area_code($area,$level_type=0){
		$address=$area['province'];
		$oldaddress=$area['province'];
		if($area['city'] && $level_type<=8){
			$address.=' '.$area['city'];
			$oldaddress.=' 直辖市';
		}
		if($area['district'] && $level_type<=7){
			$address.=' '.$area['district'];
			$oldaddress.=' '.$area['district'];
		}
		if($area['street'] && $level_type<=6){
			$address.=' '.$area['street'];
			$oldaddress.=' '.$area['street'];
		}
		$area_code=pdo_getcolumn('core_area',array('address'=>$address),'code');
		if(!$area_code){
			$isup=pdo_count('core_area',array(),'code');
			if($isup==0){
				require ROOT_D.'/update/update_area.php';
				$area_code=pdo_getcolumn('core_area',array('address'=>$address),'code');
			}else{
				$area_code=pdo_getcolumn('core_area',array('address'=>$oldaddress),'code');
				if($area_code){
					pdo_query('DROP TABLE IF EXISTS '.TABLE_PRE.'core_area;');
					require ROOT_D.'/update/update_area.php';
				}
			}
		}
		return $area_code;
	}
}